﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedLib.XmlDataModel;
using System.Xml;

namespace Tracy.DataModel
{
    public class Tag : XmlDataModel
    {
        public Tag(XmlNode node) : base(node) { }
        public Tag() : base() { }

        public string Category
        {
            get;
            set;
        }

        public string Value
        {
            get;
            set;
        }

        public override string RootNodeName
        {
            get
            {
                return "tag";
            }
        }

        protected override XmlElement GenerateXmlNode(XmlDocument doc)
        {
            XmlElement rootNode = base.GenerateXmlNode(doc);
            if (rootNode != null)
            {
                rootNode.SetAttribute("category", Category);
                rootNode.InnerText = Value;
            }
            return rootNode;
        }

        protected override void ParseRootNode(XmlElement rootNode)
        {
            if (rootNode != null)
            {
                Category = rootNode.GetAttribute("category");
                Value = rootNode.InnerText;
            }
        }

        public bool Equals(Tag anotherTag)
        {
            return (Category == anotherTag.Category && Value == anotherTag.Value);
        }
    }
}
